﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 计算器
{
    // 一个简单的计算器
    public partial class FrmCalculator : Form
    {
        public FrmCalculator()
        {
            InitializeComponent();
        }

        private void BtnAdd_Click(object sender, EventArgs e)
        {
            double firstnum, secondnum, Result;
            firstnum = Convert.ToDouble(TbxFirst.Text);
            secondnum = Convert.ToDouble(TbxSecond.Text);
            Result = firstnum + secondnum;
            TbxResult.Text = Convert.ToString(Result);
            MessageBox.Show(Convert.ToString(firstnum) + " + " + Convert.ToString(secondnum) + " = " + Convert.ToString(Result), "Addition");
        }

        private void BtnSubtract_Click(object sender, EventArgs e)
        {
            //  减去TbxFirst和TbxSecond的内容
            // 将结果显示在TbxResult中，将整个表达式显示在一个MessageBox里
            // 将字符串转换为双数，进行算术运算，然后将结果转换为字符串（两次）进行显示。
            TbxResult.Text = Convert.ToString(Convert.ToDouble(TbxFirst.Text) - Convert.ToDouble(TbxSecond.Text));
            MessageBox.Show(TbxFirst.Text + " - " + TbxSecond.Text + " = " + Convert.ToString(Convert.ToDouble(TbxFirst.Text)
                    - Convert.ToDouble(TbxSecond.Text)), "Subtraction");
        }

        private void BtnMultiply_Click(object sender, EventArgs e)
        {
            // 将TbxFirst和TbxSecond的内容相乘
            string sResult;
            sResult = Convert.ToString(Convert.ToDouble(TbxFirst.Text) * Convert.ToDouble(TbxSecond.Text));
            TbxResult.Text = sResult;
            MessageBox.Show(TbxFirst.Text + " * " + TbxSecond.Text + " = " + sResult, "Multiplication");
        }

        private void BtnDivide_Click(object sender, EventArgs e)
        {
            // 将TbxFirst的内容除以TbxSecond的内容。
            string sfirstnum, sSecondnum, sResult, sExpression;
            double dfirstnum, dSecondnum, dResult;
            sfirstnum = TbxFirst.Text;
            sSecondnum = TbxSecond.Text;
            dfirstnum = Convert.ToDouble(sfirstnum);
            dSecondnum = Convert.ToDouble(sSecondnum);
            dResult = dfirstnum / dSecondnum;
            sResult = Convert.ToString(dResult);
            TbxResult.Text = sResult;
            sExpression = sfirstnum + " / " + sSecondnum;
            sExpression = sExpression + " = " + sResult;
            MessageBox.Show(sExpression, "Division");
        }

    }
}
